home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Data 2002 May / CD Rom Data Mayıs 2002.iso / Freeware / Blitz Basic / data1.cab / Support / help / samples / spindisc.bb < prev    next >
Encoding:
Text File  |  2002-04-10  |  2.9 KB  |  115 lines

  1. ; Spin the Disc by Simon Harrison (si@si-design.co.uk)
  2.  
  3.  
  4.  
  5. ; The aim of the game is to click the disc as many times as you can before it disappears off the edge of the screen!
  6.  
  7.  
  8.  
  9. ; Set display mode values
  10.  
  11. Const width=640,height=480
  12.  
  13.  
  14.  
  15. ; Set display mode
  16.  
  17. Graphics width,height
  18.  
  19.  
  20.  
  21. ; Draw to back buffer
  22.  
  23. SetBuffer BackBuffer()
  24.  
  25.  
  26.  
  27. ; Load disc image
  28.  
  29. disc=LoadImage("graphics/disc.bmp")
  30.  
  31.  
  32.  
  33. ; Set the handle of the disc image at its centre
  34.  
  35. HandleImage disc,32,32
  36.  
  37.  
  38.  
  39. ; Set disc image rotations value
  40.  
  41. rots=64
  42.  
  43.  
  44.  
  45. ; Initialise array to store each rotated image of disc
  46.  
  47. Dim spindisc(rots)
  48.  
  49.  
  50.  
  51. ; Rotate disc image
  52.  
  53. anglestep#=360.0/rots
  54.  
  55. For discno=0 To rots-1
  56.  
  57. spindisc(discno)=CopyImage(disc)
  58.  
  59. RotateImage spindisc(discno),angle#
  60.  
  61. angle#=angle#+anglestep#
  62.  
  63. Next
  64.  
  65.  
  66.  
  67. ; Load mouse pointer image
  68.  
  69. pointer=LoadImage("graphics/pointer.bmp")
  70.  
  71.  
  72.  
  73. ; Load high score data
  74.  
  75. load=ReadFile("sdhighscore")
  76.  
  77. high=ReadLine(load)
  78.  
  79.  
  80.  
  81. ; Set font to arial size 32
  82.  
  83. font=LoadFont("arial",32)
  84.  
  85. SetFont font
  86.  
  87.  
  88.  
  89. ; Set initial disc position values
  90.  
  91. discx=width/2
  92.  
  93. discy=height/2
  94.  
  95.  
  96.  
  97. ; Repeat following loop until escape key is pressed
  98.  
  99. While Not KeyDown(1)
  100.  
  101.  
  102.  
  103. ; Seed the random number generator with the current timer value
  104.  
  105. SeedRnd(MilliSecs())
  106.  
  107.  
  108.  
  109. ; Clear the screen
  110.  
  111. Cls
  112.  
  113.  
  114.  
  115. ; Print current score to screen
  116.  
  117. Text width/2,0,score,1
  118.  
  119.  
  120.  
  121. ; Print high score to screen
  122.  
  123. Text width/2,height-32,"High: "+high,1
  124.  
  125.  
  126.  
  127. ; Update disc position values
  128.  
  129. discx=discx+discmovx
  130.  
  131. discy=discy+discmovy
  132.  
  133.  
  134.  
  135. ; Alter frame value depending on disc movement values
  136.  
  137. frame=frame+(discmovx+discmovy)
  138.  
  139.  
  140.  
  141. ; Wrap the frame values
  142.  
  143. If frame>63 Then frame=frame-64
  144.  
  145. If frame<0 Then frame=frame+64
  146.  
  147.  
  148.  
  149. ; Draw disc image to screen using current frame value
  150.  
  151. DrawImage spindisc(frame),discx,discy
  152.  
  153.  
  154.  
  155. ; Draw pointer image to screen at current mouse x and mouse y positions
  156.  
  157. DrawImage pointer,MouseX(),MouseY()
  158.  
  159.  
  160.  
  161. ; If left mouse button is not being pressed then release flag=1 (this means the mouse button has been released)
  162.  
  163. If MouseDown(1)=0 Then release=1
  164.  
  165.  
  166.  
  167. ; If pointer image overlaps disc image and left mouse button pressed...
  168.  
  169. If ImagesOverlap(pointer,MouseX(),MouseY(),disc,discx,discy)=1 And MouseDown(1)=1
  170.  
  171.  
  172.  
  173. ; If release flag=1 then randomise disc movement values
  174.  
  175. If release=1
  176.  
  177. discmovx=Rnd(0,10)-Rnd(0,10) : discmovy=Rnd(0,10)-Rnd(0,10) : score=score+1
  178.  
  179. EndIf
  180.  
  181.  
  182.  
  183. ; Release flag=0 (this means the mouse button has not yet been released since last pressing it)
  184.  
  185. release=0
  186.  
  187.  
  188.  
  189. EndIf
  190.  
  191.  
  192.  
  193. ; If disc position values are outside screen boundaries...
  194.  
  195. If discx<0-32 Or discx>width+32 Or discy<0-32 Or discy>height+32
  196.  
  197.  
  198.  
  199. ; If current score is above high score then make current score the high score and save high score
  200.  
  201. If score>high Then high=score : save=WriteFile("sdhighscore") : WriteLine save,high : CloseFile save
  202.  
  203.  
  204.  
  205. ; Reset values
  206.  
  207. score=0
  208.  
  209. discx=width/2
  210.  
  211. discy=height/2
  212.  
  213. discmovx=0
  214.  
  215. discmovy=0
  216.  
  217.  
  218.  
  219. EndIf
  220.  
  221.  
  222.  
  223. ; Flip screen buffers
  224.  
  225. Flip
  226.  
  227.  
  228.  
  229. Wend